package com.justnow.offer;

import java.util.Scanner;

/**
 * @author justnow
 * Created on 2020-09-08
 * Description
 */
public class Xiaomi02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[][] twoArray = {
                {'A', 'B', 'C', 'E'},
                {'S', 'F', 'C', 'S'},
                {'A', 'D', 'E', 'E'},
        };
        String str = scanner.nextLine();
        if (str == null || str.length() <= 0) {
            System.out.println("false");
            return;
        }
        char[] chars = str.toCharArray();
        for (int i = 0; i < twoArray.length; i++) {
            for (int j = 0; j < twoArray[0].length; j++) {
                if (dfs(twoArray, chars, i, j, 0)) {
                    System.out.println("true");
                    return;
                }

            }
        }
        System.out.println("false");
    }

    private static boolean dfs(char[][] twoArray, char[] chars, int i, int j, int index) {
        if (i >= twoArray.length || i < 0 || j >= twoArray[0].length || j < 0 || twoArray[i][j] != chars[index])
            return false;
        if (index == chars.length - 1)
            return true;
        char temp = twoArray[i][j];
        twoArray[i][j] = '/';
        boolean next = dfs(twoArray, chars, i + 1, j, index + 1) || dfs(twoArray, chars, i - 1, j, index + 1)
                || dfs(twoArray, chars, i, j + 1, index + 1) || dfs(twoArray, chars, i, j - 1, index + 1);
        twoArray[i][j] = temp;
        return next;
    }


}
